package com.shbaiche.bifenba.ui.match;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.google.gson.Gson;
import com.sevenheaven.segmentcontrol.SegmentControl;
import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.adapter.match.MatchListAdapter;
import com.shbaiche.bifenba.model.base.TransMessage;
import com.shbaiche.bifenba.model.data.CompeteVo;
import com.shbaiche.bifenba.model.match.MatchesListMessage;
import com.shbaiche.bifenba.model.match.MatchesVo;
import com.shbaiche.bifenba.net.JsonCallback;
import com.shbaiche.bifenba.net.NetApi;
import com.shbaiche.bifenba.ui.base.BaseFragment;
import com.shbaiche.bifenba.util.StringUtil;
import com.shbaiche.bifenba.util.ToastUtil;

import java.util.ArrayList;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xrecyclerview.RecyclerItemCallback;
import cn.droidlover.xrecyclerview.XRecyclerContentLayout;
import cn.droidlover.xrecyclerview.XRecyclerView;
import okhttp3.Call;

/**
 * 比赛详情-情报
 */

@SuppressLint("ValidFragment")
public class MatchDetailIntelligenceFragment extends BaseFragment {

    @BindView(R.id.layout_content_intelligence)
    LinearLayout layoutIntelligence;



    MatchesVo mMatchVo;

    @SuppressLint("ValidFragment")
    public MatchDetailIntelligenceFragment(){

    }

    public static MatchDetailIntelligenceFragment newInstance() {
        return new MatchDetailIntelligenceFragment();
    }


    @Override
    public void initData(Bundle savedInstanceState) {
        if(savedInstanceState!=null && savedInstanceState.containsKey("data")){
            mMatchVo = (MatchesVo)savedInstanceState.getSerializable("data");
        }else{
            mMatchVo = (MatchesVo)getArguments().getSerializable("data");
        }

        View view = View.inflate(getContext(),R.layout.layout_match_detail_intelligence_root,null);
        LinearLayout layoutLeft = (LinearLayout) view.findViewById(R.id.layout_content_intelligence_list_left);
        LinearLayout layoutRight = (LinearLayout) view.findViewById(R.id.layout_content_intelligence_list_right);

        for (int i = 0; i< 0;i++){
            View viewItem = View.inflate(getContext(),R.layout.layout_match_detail_intelligence_item,null);

            layoutLeft.addView(viewItem);
        }

        for (int i = 0; i< 0;i++){
            View viewItem = View.inflate(getContext(),R.layout.layout_match_detail_intelligence_item,null);

            layoutRight.addView(viewItem);
        }

        //layoutIntelligence.addView(view);


        View viewTJ = View.inflate(getContext(),R.layout.layout_match_detail_intelligence_root,null);
        LinearLayout layoutLeftTJ = (LinearLayout) viewTJ.findViewById(R.id.layout_content_intelligence_list_left);
        LinearLayout layoutRightTJ = (LinearLayout) viewTJ.findViewById(R.id.layout_content_intelligence_list_right);

        for (int i = 0; i< 0;i++){
            View viewItem = View.inflate(getContext(),R.layout.layout_match_detail_intelligence_item,null);

            layoutLeftTJ.addView(viewItem);
        }

        for (int i = 0; i< 0;i++){
            View viewItem = View.inflate(getContext(),R.layout.layout_match_detail_intelligence_item,null);

            layoutRightTJ.addView(viewItem);
        }

        //layoutIntelligence.addView(viewTJ);


    }



    public void loadData() {
        MatchesListMessage message = new MatchesListMessage();


        NetApi.matchesList(message, new JsonCallback<TransMessage>() {
            @Override
            public void onFail(Call call, Exception e, int id) {

                ToastUtil.show("onFail" + e.getMessage());
            }

            @Override
            public void onError(Call call, Exception e, int id) {

                ToastUtil.show("onFail" + e.getMessage());

            }

            @Override
            public void onResponse(TransMessage response, int id) {

                MatchesListMessage result =new Gson().fromJson(response.getMessage(),MatchesListMessage.class);
                if (StringUtil.equalsIgnoreCase(TransMessage.SuccessCode, result.getCode())) {
                    if(result!=null && result.getVoMap()!=null){
                        Log.e("t","onResponse");
                        ArrayList<MatchesVo> list = new ArrayList<MatchesVo>();
                        MatchesVo vo;
                        for (String key : result.getVoMap().keySet()){
                            //list.addAll(result.getVoMap().get(key));
                            for (int i=0;i<result.getVoMap().get(key).size();i++){
                                vo = result.getVoMap().get(key).get(i);
                                vo.dateShow = key;
                                list.add(vo);
                            }
                        }

                    }
                }else{
                    Log.e("t","onResponse getCode "+response.getCode());
                }
            }
        });





    }








    @Override
    public int getLayoutId() {
        return R.layout.fragment_match_detail_intelligence;
    }
}
